﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class news_EPioneerData : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPage = Request["page"];
            string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
            if (string.IsNullOrEmpty(newTypeId))
                newTypeId = "020103";
            ddlNewType1.SelectedValue = newTypeId;
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }
            bd(page);
        }
    }

    protected void btnPub_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerDataBLL bll = new CMS.BLL.EPioneerDataBLL();
        string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
        string[] list = hidIds.Value.Split(',');
        if (list.Length > 0 && list[0] != "")
        {
            if (string.IsNullOrEmpty(newTypeId))
                newTypeId = "020103";
            bll.UpdateNews(list, newTypeId, "1", "");
            bd(AspNetPager1.CurrentPageIndex);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('没有选中发布项');", true);
        }
    }

    protected void btnCancelPub_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerDataBLL bll = new CMS.BLL.EPioneerDataBLL();
        string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
        string[] list = hidIds.Value.Split(',');
        if (list.Length > 0 && list[0] != "")
        {
            if (string.IsNullOrEmpty(newTypeId))
                newTypeId = "020103";
            bll.UpdateNews(list, newTypeId, "0", "0");
            bd(AspNetPager1.CurrentPageIndex);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('没有选中取消发布项');", true);
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }

    private void bd(int page)
    {
        CMS.BLL.EPioneerDataBLL bll = new CMS.BLL.EPioneerDataBLL();

        string title = Server.UrlDecode(Request["title"]);
        string date = Server.UrlDecode(Request["date"]);
        string edate = Server.UrlDecode(Request["edate"]);
        string id = Request["id"];
        string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
        List<CMS.Entity.EPioneerDataModel> data = new List<CMS.Entity.EPioneerDataModel>();
        if (newTypeId == "56")
        {
            data = bll.GetDataModelPagination(title, id, date, edate);
        }
        else if (newTypeId == "54")
        {
            data = bll.GetDataModelPagination(newTypeId, title, id, date, edate, 20);
        }
        else if (newTypeId == "0")
        {
            data = bll.GetSTOCKABNORMALMSG(newTypeId, title, id, date, edate);
        }
        else if (newTypeId == "0101")
        {
            data = bll.GetNewListWhere(newTypeId, title, id, date, edate);
        }
        else if (newTypeId == "020107")
        {
            data = bll.GetNewsTextList(newTypeId, title, id, date, edate);
        }
        else
        {
            data = bll.GetNewsTextList(title, id, date, edate);
        }

        AspNetPager1.RecordCount = data.Count();
        AspNetPager1.CurrentPageIndex = page;
        IEnumerable<CMS.Entity.EPioneerDataModel> res = data.OrderByDescending(x => x.n_createdate).Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
        Repeater1.DataSource = data;
        Repeater1.DataBind();
    }
    protected void btnCho_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerDataBLL bll = new CMS.BLL.EPioneerDataBLL();
        string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
        string[] list = hidIds.Value.Split(',');
        if (list.Length > 0 && list[0] != "")
        {
            if (string.IsNullOrEmpty(newTypeId))
                newTypeId = "020103";
            bll.UpdateNews(list, newTypeId, "1", "1");
            bd(AspNetPager1.CurrentPageIndex);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('没有选中精选项');", true);
        }
    }

    protected void btnCancelCho_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerDataBLL bll = new CMS.BLL.EPioneerDataBLL();
        string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
        string[] list = hidIds.Value.Split(',');
        if (list.Length > 0 && list[0] != "")
        {
            if (string.IsNullOrEmpty(newTypeId))
                newTypeId = "020103";
            bll.UpdateNews(list, newTypeId, "", "0");
            bd(AspNetPager1.CurrentPageIndex);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('没有选中取消精选项');", true);
        }
    }

    public string GetTypeId()
    {
        string newTypeId = Server.UrlDecode(Request["newsTypeId"]);
        if (string.IsNullOrEmpty(newTypeId))
            newTypeId = "020103";
        return newTypeId;
    }
}